const fs = require('fs');
const querystring = require('querystring');

module.exports = {
  index(res){
    // 处理项目默认路径
     const data = fs.readFileSync('./index.html')
      if (data) {
        res.statusCode = 200;
        res.setHeader('Content-Type', 'text/html');
        res.end(data);
      } else {
        res.statusCode = 404;
        res.end();
      }
  },
  imageFile(url, res){
     const data = fs.readFileSync('.' + url)
      res.end(data)
  },
  login(req, res){
     let data = ''
    req.on('data', (chunk) => {
      if(chunk){
      data+=chunk
      }
    });
    req.on('end', () => {
      // res.end(querystring.stringify(querystring.parse(data)));
      res.end(JSON.stringify(querystring.parse(data)));
    });
  }
}